import java.util.Random;
import java.lang.Integer;

public class Hash
{
    public int a1;
    public int a2;
    public int a3;
    public int a4;
    public int a5;
    public int a6;

    public Hash(int a1, int a2, int a3, int a4, int a5, int a6)
    {
	this.a1 = a1;
	this.a2 = a2;
	this.a3 = a3;
	this.a4 = a4;
	this.a5 = a5;
	this.a6 = a6;
    }

    public int hash(int x)
    {
	x += x << a1;
	x ^= x >>> a2;
	x += x << a3;
	x ^= x >>> a4;
	x += x << a5;
	x ^= x >>> a6;
	return x;
    }

    public int hash2(int x)
    {
	x ^= x << a1;
	x += x >>> a2;
	x ^= x << a3;
	x += x >>> a4;
	x ^= x << a5;
	x += x >>> a6;
	return x;
    }

    public int hash33(int x)
    {
	int h = 0;
	h = ((x >>> 24) & 0xff) * 33 + h;
	h = ((x >>> 16) & 0xff)  * 33 + h;
	h = ((x >>> 8) & 0xff) * 33 + h;
	h = (x & 0xff) * 33 + h;
	return h;
    }

    public String jtest()
    {
	return Integer.toBinaryString(1 << 31);
    }

    public int[][] testit(int iter)
    {
	Random r = new Random();
	int[][] count = new int[33][32];
	for (int i = 0; i < 32; ++i) {
	    int mask = (1 << i);
	    for (int j = 0; j < iter; ++j) {
		int x = r.nextInt();
		int y = x ^ mask;
		int distance = Integer.bitCount(hash33(x) ^ hash33(y));
		count[distance][i]++;
	    }
	}
	return count;
    }
}
